<template>
  <div class="container-fluid m-0 p-0">
    <h5 class="text-center text-success">挂机可以让您在不在线或者没有时间手动操作时提高自己。</h5>
    <h4 class="text-center" style="color: DodgerBlue">{{offstate}}</h4>
    <div class="row">
      <div class="col" v-for="(desc, keydesc) of this.offcards" :key=keydesc>
        <span :style="{color: desc.color}">{{desc.desc}}</span>
        <button style="height:50px" :class=btnclass(desc.state) :disabled=btndisable(desc.state) :name=desc.state @click=onoffline($event)>{{desc.btnname}}</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      offinfo: {},
      offcards: [
        {
          btnname: '外出修行',
          state: 1,
          color: 'DeepSkyBlue',
          desc: '外出修行侧重获得装备和道具，也可提升部分道行和潜能。'
        },
        {
          btnname: '闭关修炼',
          state: 2,
          color: 'DarkOrange',
          desc: '闭关修炼侧重获得道行和潜能，偶尔可能炼丹获得丹药等。'
        },
        {
          btnname: '停止挂机',
          state: 0,
          color: 'Gray',
          desc: '停止挂机让您取消当前挂机状态，方可手动进行游戏功能。'
        }
      ]
    }
  },
  components: {
    // websocket: websocket
  },
  methods: {
    btndisable: function (state) {
      if (this.offinfo.OfflineMode === 0) {
        return state === 0
      } else {
        return state !== 0
      }
    },
    btnclass: function (state) {
      var disable = this.btndisable(state)
      return (disable ? 'btn-secondary' : 'btn-success') + ' btn btn-block p-0 m-0'
    },
    onoffline: function (event) {
      var req = this.wsreq('C2G_CHAR_OFFLINE')
      req.OfflineMode = Number(event.srcElement.name)
      this.wssend(req)
    },
    G2C: function (pid, rsp, success, result) {
      switch (pid) {
        case 'G2C_CHAR_OFFLINEINFO':
          this.offinfo = rsp.InfoOffline
          break
        case 'G2C_CHAR_OFFLINE':
          this.offinfo = rsp.InfoOffline
          if (this.offinfo.OfflineMode === 0) {
            this.jxtoast('你停止了挂机。')
            this.jxwdtextmud('你#DarkGreen#停止了挂机。')
          } else if (this.offinfo.OfflineMode === 1) {
            this.jxtoast('你开始外出修行。')
            this.jxwdtextmud('你开始#DodgerBlue#外出修行。')
          } else if (this.offinfo.OfflineMode === 2) {
            this.jxtoast('你开始闭关修炼。')
            this.jxwdtextmud('你开始#Orange#闭关修炼。')
          }
          break
        default:
          // 这里是没有找到对应的值处理
          break
      }
    }
  },
  computed: {
    offstate: function () {
      if (this.offinfo.OfflineMode === 1) {
        return '当前状态：外出修行中' + this.offinfo.OfflineTs
      } else if (this.offinfo.OfflineMode === 2) {
        return '当前状态：闭关修炼中' + this.offinfo.OfflineTs
      }
      return '当前状态：不在挂机'
    }
  }
}
</script>

<style scoped>
</style>
